home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995…tember: Reference Library / Dev.CD Sep 95 RL / Dev.CD Sep 95 RL.toast / mac / Technical Documentation / develop / develop Issue 3 code / ISO 9660 & High Sierra / iso9660 ƒ / i⁄o.c < prev    next >
Encoding:
Text File  |  1990-06-04  |  4.7 KB  |  206 lines  |  [TEXT/KAHL]

  1. /************************************************************************
  2.  *
  3.  *    Copyright © 1990    Apple Computer, Inc.  All rights reserved.
  4.  *
  5.  ************************************************************************/
  6.  
  7. #include <stdio.h>
  8. #include <FileMgr.h>
  9. #include <HFS.h>
  10. #define ISO
  11.  
  12. #include "HighSierra.h"
  13. #include "BuildISO.h"
  14.  
  15.  
  16. /************************************************************************
  17.  *
  18.  *  Function:        isoOpen
  19.  *
  20.  *  Purpose:        Open the driver for i/o
  21.  *
  22.  *  Returns:        OSErr
  23.  *
  24.  *  Side Effects:    fills *RefNum with valid reference number for driver.
  25.  *
  26.  *  Description:    Issue Mac OS PBOpen call to open the driver.  We
  27.  *                    can use the returned reference number to access the
  28.  *                    driver for raw i/o.
  29.  *
  30.  *
  31.  ************************************************************************/
  32. OSErr
  33. isoOpen(fn, RefNum)
  34. StringPtr    fn;
  35. short        *RefNum;
  36. {
  37.     ParamBlockRec    pb;
  38.     OSErr    result;
  39.     
  40.     pb.ioParam.ioNamePtr = fn;
  41.     pb.ioParam.ioCompletion = 0;
  42.     pb.ioParam.ioPermssn = fsRdPerm;
  43.     result = PBOpen(&pb, false);
  44.     *RefNum = pb.ioParam.ioRefNum;
  45.     
  46.     return result;
  47. }
  48.  
  49. /************************************************************************
  50.  *
  51.  *  Function:    isoRead
  52.  *
  53.  *  Purpose:    read from the driver
  54.  *
  55.  *  Returns:    OSErr
  56.  *
  57.  *  Side Effects:    fills dest with contents for 'count' bytes.
  58.  *
  59.  *  Description:    do a call to the Mac CD driver to read a specified
  60.  *                    number of bytes starting at 'offset'.  The number of
  61.  *                    bytes must be a multiple of 512, or this call won't
  62.  *                    work (the driver returns an error)
  63.  *
  64.  ************************************************************************/
  65. OSErr
  66. isoRead(referenceNumber, dest, count, offset)
  67. short    referenceNumber;
  68. Ptr        dest;
  69. long    count;
  70. long    offset;
  71. {
  72.     OSErr result;
  73.     ParamBlockRec    io;
  74.     
  75.     ClearOut((char *)&io, sizeof(io));
  76.     io.ioParam.ioCompletion = NULL;
  77.     io.ioParam.ioVRefNum = 0;
  78.     io.ioParam.ioRefNum = referenceNumber;
  79.     io.ioParam.ioBuffer = dest;
  80.     io.ioParam.ioReqCount = count;
  81.     io.ioParam.ioPosMode = fsFromStart;
  82.     io.ioParam.ioPosOffset = offset;
  83.     result = PBRead(&io, false);
  84.     
  85.     if (result != noErr)
  86.         ErrorMsg("PBRead failed. ioActCount = %d", io.ioParam.ioActCount);
  87.     
  88.     return result;
  89. }
  90.  
  91.  
  92. /************************************************************************
  93.  *
  94.  *  Function:    isoWrite
  95.  *
  96.  *  Purpose:    Write to the driver
  97.  *
  98.  *  Returns:    OSErr
  99.  *
  100.  *  Side Effects:    none
  101.  *
  102.  *  Description:    do a call to the Mac CD driver to write a specified
  103.  *                    number of bytes starting at 'offset'.  The number of
  104.  *                    bytes must be a multiple of 512, or this call won't
  105.  *                    work (the driver returns an error.)
  106.  *
  107.  ************************************************************************/
  108. OSErr
  109. isoWrite(referenceNumber, buffer, count, offset)
  110. short    referenceNumber;
  111. Ptr        buffer;
  112. long    count;
  113. long    offset;
  114. {
  115.     OSErr result;
  116.     ParamBlockRec    io;
  117.     
  118.     ClearOut((char *)&io, sizeof(io));
  119.     io.ioParam.ioCompletion = NULL;
  120.     io.ioParam.ioVRefNum = 1;
  121.     io.ioParam.ioRefNum = referenceNumber;
  122.     io.ioParam.ioBuffer = buffer;
  123.     io.ioParam.ioReqCount = count;
  124.     io.ioParam.ioPosMode = fsFromStart;
  125.     io.ioParam.ioPosOffset = offset;
  126.     result = PBWrite(&io, false);
  127.     
  128.     if (result != noErr)
  129.         ErrorMsg("PBWrite failed. result = %d", result);
  130.     
  131.     return result;
  132. }
  133.  
  134.  
  135. /************************************************************************
  136.  *
  137.  *  Function:        ZeroDisk
  138.  *
  139.  *  Purpose:        Clean out this disk so it's not HFS anymore
  140.  *
  141.  *  Returns:        OSErr
  142.  *
  143.  *  Side Effects:    zero out a lot of disk
  144.  *
  145.  *  Description:    loop, doing a write of zeros.
  146.  *
  147.  ************************************************************************/
  148. OSErr
  149. ZeroDisk(referenceNumber)
  150. short    referenceNumber;
  151. {
  152.     Ptr        noBuffer;
  153.     short    i;
  154.     short    j;
  155.     OSErr    result;
  156.     CursHandle    cursor;
  157.     
  158.     noBuffer = NewPtr(CDBLKSIZE);
  159.     if (noBuffer == NULL)
  160.         return (MemError());
  161.     for (i = 0; i < CDBLKSIZE; i++)
  162.         noBuffer[i] = 0;
  163.  
  164.     result = noErr;
  165.  
  166.      cursor = GetCursor(watchCursor);
  167.      if (!cursor)
  168.          SetCursor(*cursor);
  169.     for (i = 0, j = 0; i < 10 && result == noErr; i++, j++)
  170.         result = isoWrite(referenceNumber, noBuffer, (long)CDBLKSIZE, (long) j*CDBLKSIZE);
  171.     
  172.     SetCursor(&arrow);
  173.     DisposPtr(noBuffer);
  174.     return result;
  175. }
  176.  
  177. /************************************************************************
  178.  *
  179.  *  Function:        GetDriveNumber
  180.  *
  181.  *  Purpose:        Get the driver number
  182.  *
  183.  *  Returns:        short.  The driver number
  184.  *
  185.  *  Side Effects:    none.
  186.  *
  187.  *  Description:    PBHGetVInfo() will retrieve the driver
  188.  *                    number, given the vRefNum associated with a file.
  189.  *
  190.  ************************************************************************/
  191. short
  192. GetDriveNumber(vRefNum)
  193. short    vRefNum;
  194. {
  195.     HParamBlockRec    io;
  196.     
  197.     io.volumeParam.ioCompletion = NULL;
  198.     io.volumeParam.ioNamePtr = NULL;
  199.     io.volumeParam.ioVRefNum = vRefNum;
  200.     io.volumeParam.ioVolIndex = 0;
  201.     PBHGetVInfo(&io, false);
  202.     return io.volumeParam.ioVDrvInfo;
  203. }
  204.  
  205.  
  206.